package com.weiwei.diancan.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weiwei.diancan.R;
import com.weiwei.diancan.bean.LoginBean;

import java.util.List;


/**
 * 左侧菜单ListView的适配器
 * @author Administrator
 *
 */
public class MenuOpenAdapter extends BaseAdapter{

	private Context context;
	private int selectItem = 0;
	private List<LoginBean.MenuListBean> data;

	public MenuOpenAdapter(Context context, List<LoginBean.MenuListBean> data) {
		this.context = context;
		this.data = data;
	}

	public List<LoginBean.MenuListBean> getData() {
		return data;
	}

	public void setData(List<LoginBean.MenuListBean> data) {
		this.data = data;
		notifyDataSetChanged();
	}

	public int getSelectItem() {
		return selectItem;
	}

	public void setSelectItem(int selectItem) {
		this.selectItem = selectItem;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		if(arg1 == null) {
			holder = new ViewHolder();
			arg1 = View.inflate(context, R.layout.item_main_type, null);
			holder.tv_name = (TextView)arg1.findViewById(R.id.tv);
			holder.ll_item = (LinearLayout)arg1.findViewById(R.id.ll_item);
			arg1.setTag(holder);
		}else {
			holder = (ViewHolder)arg1.getTag();
		}
		if(position == selectItem){
			holder.ll_item.setBackgroundColor(Color.WHITE);
			holder.tv_name.setTextColor(context.getResources().getColor(R.color.my_titler));
		}else {
			holder.ll_item.setBackgroundColor(context.getResources().getColor(R.color.my_color));
			holder.tv_name.setTextColor(context.getResources().getColor(R.color.home_tv_extra));
		}
		holder.tv_name.setText(data.get(position).getType_name());
		return arg1;
	}
	static class ViewHolder{
		private TextView tv_name;
		private LinearLayout ll_item;
	}
}
